<?php

/**
 * Description of WrapperApp
 *
 * @author EaDeveloper
 */
abstract class ReportBase {

    public $paramPage;
    public $resultPage;
    public $rootPath;
    public $key;
    public $label;
    public $subtitle;
    public $db;
    public $lastQuery;
    #public $callbackRow;
    #public $callbackSql;
    public $lastResult = null;
    public $titulo;
    public $parametros;

    function __construct($crow, $paramPage, $resultPage, $rootPath, $key, $label, $csql = null) {
        #   $this->fields = $fields;
        $this->callbackSql = $csql; //funcion que genera sql
        $this->callbackRow = $crow; //funcion para cada fila generada
        $this->paramPage = $paramPage;
        $this->resultPage = $resultPage;
        $this->rootPath = $rootPath;
        $this->key = $key;
        $this->label = $label;
    }

    /**
     * @see Genera el reportes con su pantalla de parametros!
     */
    public function show($ret = false) {
        if ($ret) {
            ob_start();
            $this->getContent();
            $str = ob_get_contents();
            ob_end_clean();
            return $str;
        } else {
            $this->getContent();
        }
    }

    public function getContent() {
        $params = getParam("params");
        if (isEmpty($params)) {
            echo '<div id="maindiv">';
            include RPT_PATH . "/$this->key/$this->paramPage";
            echo '</div>';
        } else {
            include RPT_PATH . "/$this->key/$this->resultPage";
        }
    }

    /**
     * Genera una consulta SQL en base a los callbacks programados
     * @param type $pagMode
     * @return type 
     */
    public function query($sql) {
        return $this->db->queryToArray($sql);
    }

}

?>
